import { createStore } from 'vuex'
// vue3.0中createStore来创建vuex实例
import user from './modules/user'
import cart from './modules/cart'
import category from './modules/category'

import createPersistedstate from 'vuex-persistedstate'
// import * as Cookies from 'js-cookie'
// 创建vuex仓库并导出
export default createStore({
  strict: true,
  modules: {
    user,
    cart,
    category
  },
  plugins: [ // 使用vuex-persistedstate插件来进行持久化
    createPersistedstate({
      // storage: {
      //   getItem: (key) => Cookies.get(key),
      //   setItem: (key, value) =>
      //     Cookies.set(key, value, { expires: 7 }), // expires指过期时间单位：天
      //   removeItem: (key) => Cookies.remove(key)
      // },
      key: 'rabbit-store',
      paths: ['user', 'cart']
    })
  ]
})
